package cn.yj.wx.pay.service.handler;

import cn.yj.common.emums.PayFrom;
import cn.yj.wx.pay.enrity.PayOrderResult;
import cn.yj.wx.pay.enrity.WechatPayRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * 商户Native支付下单接口，微信后台系统返回链接参数code_url，商户后台系统将code_url值生成二维码图片，用户使用微信客户端扫码后发起支付。
 *
 * @author 永健
 * @since 2021-09-22 16:33
 */
public class NativePay extends AbstractWxPay<PayOrderResult, WechatPayRequest> {
    private static final Logger LOGGER = LoggerFactory.getLogger(NativePay.class);

    private static final String PAY_URL = "https://api.mch.weixin.qq.com/v3/pay/transactions/native";

    /**
     * 需要将结果 code_url 生成二维码方可扫码支付 weixin://wxpay/bizpayurl?pr=bhC4kbZzz"
     *
     * @param wechatPayRequest
     *
     * @throws IOException
     */
    @Override
    public PayOrderResult underOrder(WechatPayRequest wechatPayRequest) {
        return super.doUnderOrder(PAY_URL, wechatPayRequest);
    }

    @Override
    public boolean support(PayFrom payFrom) {
        return payFrom == PayFrom.NATIVE;
    }
}
